package com.example.cshaoshao.demo.activities;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.cshaoshao.demo.R;

/**
 * Created by cshaoshao on 2017/6/26.
 */

public class MessageActivity extends AppCompatActivity
{
    private TextView textView;
    private Button button;
    private Handler handler=new Handler()
    {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if(msg.what==1)
            {
                textView.setText("嘿嘿");
            }
        }
    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button= (Button) findViewById(R.id.button);
        textView= (TextView) findViewById(R.id.textview5);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                new Thread(new Runnable() {
                    @Override
                    public void run()
                    {
                        Message message=new Message();
                        message.what=1;
                        handler.sendMessage(message);

                    }
                }).start();

            }
        });
//        button.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                handler.post(new Runnable() {
//                    @Override
//                    public void run() {
//                        textView.setText("单击成功");
//                    }
//                });
//            }
//        });
    }
}
